﻿package pages {
	import com.gaiaframework.templates.AbstractPage;
	import com.gaiaframework.events.*;
	import com.gaiaframework.debug.*;
	import com.gaiaframework.api.*;

	import flash.display.*;
	import flash.events.*;
	import flash.utils.getDefinitionByName;

	import gs.*;

	public class NavPage extends AbstractPage {	
		public function NavPage() {
			super();
			alpha = 0;
			creat();
		}

		
		//PRIVATE METHOD
		private function creat() : void {			
			//TODO 导航菜单
			var NavBtn:Class = getDefinitionByName("NavButton") as Class;
			for(var i : uint = 0;i < 7; i++) {
				var btn : MovieClip = new NavBtn() as MovieClip;
				btn.buttonMode = true;
				btn.mouseChildren = false;
				btn.x = (btn.width + 5) * i + 100;
				btn.y = 450;
				btn.gotoAndStop(i+1);
				//XXX 注意，pid在后面跳转的时候要用到。
				btn.pid = i;
				btn.addEventListener(MouseEvent.CLICK, onClickHandler);
				addChild(btn);
			}
		}

		//菜单按钮点击
		private function onClickHandler(e : MouseEvent) : void {
			var btn : MovieClip = e.currentTarget as MovieClip;
			var link:String = "index/nav/" + Model.getPagesWithId(btn.pid);
			//  改变跳转方向
			Model.instance.dir = Model.JUMP;
			Model.instance.pid = btn.pid;
			Gaia.api.goto(link);
		}

		//XXX 修改加载方式
		//  如:是否先加载完成再淡入淡出,
		//  详细看Gaia文档:http://www.gaiaflashframework.com/wiki/index.php?title=The_Gaia_Flow
		private function changeFlow() : void {
			Gaia.api.setDefaultFlow(Gaia.CROSS);
		}

		
		//PUBLIC METHOD
		override public function transitionIn() : void {
			super.transitionIn();
			changeFlow();
			TweenLite.to(this, 0.3, {alpha:1, onComplete:transitionInComplete});
		}

		override public function transitionOut() : void {
			super.transitionOut();
			TweenLite.to(this, 0.3, {alpha:0, onComplete:transitionOutComplete});
		}
	}
}
